package com.school.revervationSys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.school.revervationSys.entity.TestManage;
import com.school.revervationSys.entity.TestQuestion;
import com.school.revervationSys.entity.User;
import com.school.revervationSys.mapper.TestManageMapper;
import com.school.revervationSys.mapper.UserMapper;
import com.school.revervationSys.service.TestManagerService;
import com.school.revervationSys.service.TestQuestionService;
import org.junit.platform.commons.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TestManageServiceImpl extends ServiceImpl<TestManageMapper, TestManage> implements TestManagerService {


    @Autowired
    private TestQuestionService questionService;

    public boolean addTestManager(TestManage testManage) {
        return this.save(testManage);
    }

    public boolean updateTestManage(TestManage testManage) {
        return this.updateById(testManage);
    }

    public boolean delete(Integer testManageId) {

        return this.removeById(testManageId);
    }
    public boolean batchDelete(List<Integer> ids) {

        return this.removeByIds(ids);
    }

    public List<TestManage> testManageList(String title){

        List<TestManage> list = this.list(new QueryWrapper<TestManage>().lambda().like(StringUtils.isNotBlank(title), TestManage::getTitle, title));
        list.forEach(l->{
            List<TestQuestion> testQuestions = questionService.questionList(l.getId());
            if(testQuestions!=null&&testQuestions.size()>0)
            l.setQuestionList(testQuestions);
        });



        return list;


    }




}
